package sample.tangocho.activity;

import sample.tangocho.model.Card;
import sample.tangocho.service.EditCardService;
import sample.tangocho.service.EditCardServiceImpl;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class EditCardActivity extends Activity {
	
	private EditCardService editCardService;
	
	private int cardId;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_card);

		// TODO DI
        editCardService = new EditCardServiceImpl(getApplicationContext());
        
        Intent intent = getIntent();
        cardId = intent.getIntExtra("cardId", -1);

		EditText frontText = (EditText) findViewById(R.id.front_edittext_edit);
		EditText backText = (EditText) findViewById(R.id.back_edittext_edit);
		
		frontText.setText(intent.getStringExtra("frontText"));
		backText.setText(intent.getStringExtra("backText"));
    }

	public void editCard(View view) {
		EditText frontText = (EditText) findViewById(R.id.front_edittext_edit);
		EditText backText = (EditText) findViewById(R.id.back_edittext_edit);
		
		Card card = new Card();
		card.setId(cardId);
		
		card.setFrontText(frontText.getText().toString());
		card.setBackText(backText.getText().toString());
		editCardService.editCard(card);
		
		Toast.makeText(this, "変更しました", Toast.LENGTH_SHORT).show();
		
		finish();
	}
}
